﻿
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region ProOrderPublic Model -(by fangyifeng at 2014/1/1 10:27:53)

	/// <summary>
	/// ProOrderPublic object'ProOrderPublic'.
	/// </summary>
    [Serializable]
	public class ProOrderPublic : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected decimal _quantity;
		protected string _siteCode;
        protected string _BarCodeGuid;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public ProOrderPublic() { }

		public ProOrderPublic( decimal quantity, string siteCode )
		{
			this._quantity = quantity;
			this._siteCode = siteCode;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual decimal Quantity
		{
			get { return _quantity; }
			set { _quantity = value; }
		}

		public virtual string SiteCode
		{
			get { return _siteCode; }
			set
			{
				if ( value != null && value.Length > 30)
					throw new ArgumentOutOfRangeException("Invalid value for SiteCode", value, value.ToString());
				_siteCode = value;
			}
		}
        public virtual string BarCodeGuid
		{
            get { return _BarCodeGuid; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for SiteCode", value, value.ToString());
                _BarCodeGuid = value;
			}
		}
        
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is ProOrderPublic))
				throw new InvalidCastException("This object is not of type ProOrderPublic");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((ProOrderPublic)obj).Id);
					break;
				case "Quantity":
					relativeValue = (this.Quantity != null) ? this.Quantity.CompareTo(((ProOrderPublic)obj).Quantity) : -1;
					break;
				case "SiteCode":
					relativeValue = (this.SiteCode != null) ? this.SiteCode.CompareTo(((ProOrderPublic)obj).SiteCode) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (ProOrderPublic.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
